//设备列表
$(document).ready(function () {
    $.jgrid.defaults.styleUI = "Bootstrap";
    $("#table_list_1").jqGrid({
        data: [],
        datatype: "local",
        recordtext:"{0} - {1}\u3000"+domain.language.$t('dev_gong')+" {2} "+domain.language.$t('dev_tiao'),
        pgtext: "{0} "+domain.language.$t('dev_gong')+" {1} "+domain.language.$t('dev_ye'),  
        emptyrecords: domain.language.$t('dev_wsjxs'),
        shrinkToFit: true,
        autoScroll: true,
        autowidth: true,
        rowNum: 20,
        rowList: [10, 20, 30, 60, 90, 100, 200, 500],
        //colNames: ["编号", "名称", "手机号码"],
        colModel: [{
            name: 'devicenumber', index: 'devicenumber', align: "center", width: 10, label: domain.language.$t('dev_bianhao'), align: 'center',


        },
        {
            name: 'co_id', index: 'co_id', align: "center", width: 15, label:domain.language.$t('dev_bianhao'), align: 'center', hidden: true,


        },


        {
            name: 'devicename', index: 'devicename', align: "center", width: 8, label:domain.language.$t('dev_mingcheng'), align: 'center',


        },

        {
            name: 'co_name', index: 'co_name', align: "center", width: 10, label: domain.language.$t('dev_ssdw'), align: 'center',


        },



        {
            name: 'type', index: 'type', align: "center", width: 10, label:domain.language.$t('dev_leixing'), align: 'center',
            formatter: function (value, options, row) {

                if (value == "0") {


                    return domain.language.$t('dev_sblx1_ds');

                }

                if (value == "1") {

                    return domain.language.$t('dev_sblx2_ss');
                }

                if (value == "2") {

                    return domain.language.$t('dev_sblx3_qc');
                }

                if (value == "3") {

                    return domain.language.$t('dev_sblx4_az');
                }

            }
        },
        {
            name: 'width', index: 'width', align: "center", width: 10, label: domain.language.$t('dev_pingkuan'), align: 'center',


        },
        {
            name: 'high', index: 'high', align: "center", width: 10, label:domain.language.$t('dev_pinggao'), align: 'center',
        },

        {
            name: 'isonline', index: 'isonline', align: "center", width: 10, label:domain.language.$t('dev_zhuangtai'), align: 'center',
            formatter: function (value, options, row) {
                if (value == "1") {
                    value = "<img src=static/img/zx.png class=img-rounded style=width:36px;>";

                } else {
                    value = "<img src=static/img/lx.png class=img-rounded style=width:32px;>";


                }
                return value;

            }

        },
        {
            name: 'lastonlinetime', index: 'lastonlinetime', align: "center", width: 10, label: domain.language.$t('dev_zhzxsj'), align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd hh:mm:ss");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }


        },


        ],
        pager: "#pager_list_1",
        viewrecords: true,
        caption: domain.language.$t('dev_sblb'),
        hidegrid: false,
        multiselect: true,
        ondblClickRow: function (row) {


            $("#update").click();
            modify(row);
            // $('#myModal').modal('show')

        },
        onPaging: function (pageBtn) {
            console.log(":" + pageBtn);
            //	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数
            var re_page = $("#table_list_1").getGridParam('page');//获取返回的当前页
            var re_rowNum = $("#table_list_1").getGridParam('rowNum');//获取每页数
            var re_total = $("#table_list_1").getGridParam('lastpage');//获取总页数
            //alert(re_total);

            if (pageBtn === "next") {
                // initJqgrid(re_page+1,re_rowNum);
                // if()
                pageval = pageval + 1;
                cxlist();
            }
            if (pageBtn === "prev") {

                pageval = pageval - 1; cxlist();
            }

            if (pageBtn == "last") {

                pageval = re_total;

                cxlist();

            }
            if (pageBtn == "first") {

                pageval = 1;

                cxlist();

            }

            if (pageBtn == "records") {

                sizeval = $(".ui-pg-selbox").val();
                pageval = 1;
                cxlist();
            }

            // $("#table_list_1").setGridWidth($(".panel-primary").width());

        }

    });
    cxlist();

    $("#table_list_1").setGridHeight($(window).height() * 0.51);

    $(window).resize(function () {
        // $("#table_list_1").setGridWidth($(window).width() *0.5);
        $("#table_list_1").setGridHeight($(window).height() * 0.51);
    });

});



var sizeval = 20;
var pageval = 1;
var usernameval = $("#usnameval").val();
var conameval = "";
var json = "";


window.cxlist = function () {
    $.ajax({
        type: "POST",
        url: domain.testUrl + "/Threeinjection/DeviceManagement/queryDevicePaging",
        data: { size: sizeval, page: pageval, "type": $("#typecx").val(), "coid": sessionStorage.getItem("coid"), devicenumber: $("#usnameval").val(), sessionid: sessionStorage.getItem("sid") },
        success: function (response) {
            //console.log(response);
            json = response;
            var data = JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },
            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');

            var re_records = $("#table_list_1").getGridParam('records');

            if (re_records == 0 || re_records == null) {
                if ($(".norecords").html() == null) {
                    $("#usnameval").val("");
                    $("#table_list_1").parent().append("<div class=\"norecords\">"+domain.language.$t('dev_meiyoufhsj')+"</div>");
                }
                $(".norecords").show();
            } else {

                $(".norecords").hide();
            }

            ///alert(json);


            $("#table_list_1").setGridHeight($(window).height() * 0.51);


        }


    });
}



$(function () {

    $("#gprsTable table tr").css({ "display": "table-row" });
    $("#brightness input[name='points']").css({ "width": "50px", "height": "22px" });
    $("#param input[name='points']").css({ "width": "100px" });
    
    //起始时间 
    // $('.time').clockTimePicker({});

    cxlist();
    if (sessionStorage.getItem("isgroup") == "1") {
        //chen,不太明白控制了哪个隐藏
        // $(".row :last form label").eq(2).hide();
        $("#typecx").hide();
    }

    $("form button").eq(0).click(function () {
        

        cxlist();

    });
    $("#first .btn").click(function () {
        $("#modalLong").show();
    });

    $("#modalLong .btn:last").click(function () {
        $("#modalLong").hide();
    });

    //定时加载
    var count = $("#timeCount option:last").val();
    for (var i = 1; i <= parseInt(count); i++) {
        showTimer('timer' + i, 1);
    }
    //开关屏加载
    var srcreenCount = $("#timeScreenCount option:last").val();
    for (var j = 1; j <= parseInt(srcreenCount); j++) {
        showTimer('stimer' + j, 1);
    }
    for (var k = 1; k <= parseInt(srcreenCount); k++) {
        showTimer('etimer' + k, 1);
    }

    //定时，开关初始值显示
    setTimeout(function () {
        $("#timer1").find("input:eq(0),input:eq(2)").val("00");
        screenchange();
    }, 1000);

    //扫描按钮触发file上传文件
    $("#scanning").click(function () {
        $("#file").click();
    });
    //获取浏览的文件
    $('#file').change(function () {

    });


    if (sessionStorage.getItem("roleId") == "2") {

        $("#zl option:eq(2)").hide();

    }


    $("#yerOrNo").change(function () {
        if ($(this).is(":checked")) {
            $(this).parent().next().show();
        } else {
            $(this).parent().next().hide();
        }
    });
   //屏宽
    $("#param input:first").bind('input propertychange', function () {
        if (parseInt($(this).val()) > 1000) {

            $(this).val(256);
        }
        var val = $(this).val().substr(0, 1);
        if (val == "0") {
            $(this).val(0);
        }
    });
    //屏高
    $("#param input:eq(1)").bind('input propertychange', function () {
        if (parseInt($(this).val()) > 1000) {

            $(this).val(64);
        }
        var val = $(this).val().substr(0, 1);
        if (val == "0") {
            $(this).val(0);
        }
    });
    //节目容量
    $("#param input:eq(2)").bind('input propertychange', function () {
        if (parseInt($(this).val()) > 127) {

            $(this).val(127);
        }
        var val = $(this).val().substr(0, 1);
        if (val == "0") {
            $(this).val(0);
        }
    });

    //选择固定IP还是域名来显示默认值
    $("#ipType").click(function () {

        if ($("#ipType").val() == "0") {
            $("#DNS").attr("readonly", true);
            $("#ip").attr("readonly", false);
            $("#DNS").val("");

        } else {
            $("#DNS").attr("readonly", false);
            $("#ip").val("");
            $("#ip").attr("readonly", true);
            $("#port").val("");
        }

    });

    $("#ip").blur(function () {
        //根据ip默认显示端口
        if ($("#ip").val() == "119.23.148.39") {
            $("#port").val("9008");
        }
    });


    $("#list1,#list2,#list3").hide();

    //左边菜单栏隐藏显示
    $('.nav-item>a').on('click', function () {
        if (!$('.nav').hasClass('nav-mini')) {
            if ($(this).next().css('display') == "none") {
                $('.nav-item').children('ul').hide();
                $(this).next('ul').show();
                $(this).parent('li').addClass('nav-show');
                $(this).parent('li').siblings('li').removeClass('nav-show');
                console.log("打开了")
            } else {
                $(this).next('ul').hide();
                $('.nav-item.nav-show').removeClass('nav-show');
            }
        }
    });


    //扩展参数:关掉弹窗里的弹窗
    $("#modalLong btn:eq(1)").click(function () {
        $("#modalLong").hide();
    });

});




//亮度、时间个数选择
window.lightchange = function () {
    for (var i = 1; i <= 4; i++) {
        //先全部禁用
        $("#timer" + i).find("input").attr("disabled", true);
        $("#timer" + i).css("color", "gainsboro");

        $("#brightness").find("input[type='number']:eq(" + i + ")").attr("disabled", true);
    }

    for (var i = 1; i <= parseInt($("#timeCount").val()); i++) {
        //根据选择个数来设置
        if ($("#timeCount").val() > 1) {
            var ii = parseInt(i) - 1;
            $("#brightness").find("input[type='number']:eq(" + ii + ")").removeAttr("disabled");
            $("#timer" + i).find("input").removeAttr("disabled");
            $("#timer" + i).css("color", "");
        }
    }
}


//开关屏个数选择
window.screenchange = function () {
    for (var i = 1; i <= 4; i++) {
        //先全部禁用
        $("#stimer" + i).find("input").attr("disabled", true);
        $("#stimer" + i).css("color", "gainsboro");
        $("#etimer" + i).find("input").attr("disabled", true);
        $("#etimer" + i).css("color", "gainsboro");
    }
    for (var i = 1; i <= parseInt($("#timeScreenCount").val()); i++) {
        //根据选择个数来设置

        $("#stimer" + i).find("input").removeAttr("disabled");
        $("#stimer" + i).css("color", "");
        $("#etimer" + i).find("input").removeAttr("disabled");
        $("#etimer" + i).css("color", "");

    }
}

//ip格式
function isValidIP(ip) {
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    return reg.test(ip);
}


//基本参数复选框的值
window.Choice = function (obj) {
    if ($(obj).val() == "0") {
        $(obj).val(1)
    } else {
        $(obj).val(0);
    }
}



//上传文件
var fileId = "";

window.fileload = function (th) {
    var file = $("#file1")[0].files[0];
    //字符串接收split默认第一个数组值，如果直接用全部值都会获取出来
    
    var suffix = file.name.split('.');
    var reg = new RegExp(/bin$/, 'ig');
    $(th).prev().val(file.name);
    if (!reg.test(suffix)) {
        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_gjgsbd'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        $("#file1").val("");
        $(th).prev().val(domain.language.$t('dev_xzwenjian'));
        return false;
    }

    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (e) {

        var formData = new FormData();
        formData.append('file', $("#file1")[0].files[0]);
        $.ajax({
            url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    fileId = data.fileId;
                    // swal(domain.language.$t('dev_success'), "", "success");
                } else {
                    // swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                }
            }
        });

    }
}



//上传字库
window.fileload1 = function (th) {
    var file = $("#file2")[0].files[0];
    $(th).prev().val(file.name);
    var suffix = file.name.split('.');
    var reg = new RegExp(/(dzk|tbl)$/, 'ig');
    if (!reg.test(suffix)) {
        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_zkgsbd'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        $("#file2").val("");
        $(th).prev().val(domain.language.$t('dev_xzwenjian'));
        // console.log("后缀" + reg)
        return false;
    }



    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (e) {

        var formData = new FormData();
        formData.append('file', $("#file2")[0].files[0]);
        $.ajax({
            url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    fileId = data.fileId;
                    // swal(domain.language.$t('dev_success'), "", "success");
                } else {
                    // swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                }
            }
        });

    }
}

$(function () {

    /**基本参数 */
    $("#sup").click(function () {

        if ($("#ledclkmultiple").is(":checked")) {
            $(this).val(0);

        } else {
            $(this).val(1);
        }

        var idval = defaull();
        //var jsonval={};
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
           
            return;
        }

        if ($("#param input:first").val() == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_qxzpk'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if (parseInt($("#param input:first").val()) < 16) {
            swal(domain.language.$t('tishi'), domain.language.$t('pkbxy16'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        } if ($("#param input:eq(1)").val() == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_qxzpg'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if (parseInt($("#param input:eq(1)").val()) < 16) {
            swal(domain.language.$t('tishi'), domain.language.$t('pgbxy16'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if ($("#param input:eq(2)").val() == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_qxzjmsl'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        } if (parseInt($("#param input:eq(2)").val()) < 0 || parseInt($("#param input:eq(2)").val()) > 127) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_jmsl127'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        var rgbcolor = $("#rgbcolor").val();
        var arr = rgbcolor.split(',');
        console.log("颜色" + arr[0] + "," + arr[1] + "," + arr[2]);
        //扩展参数
        var kuoarr = new Array(0, parseInt(arr[0]), parseInt(arr[1]), parseInt(arr[2]), 3,
            parseInt($("#ledColumnChip").val()), parseInt($("#ledRowChip").val()), parseInt($("#ledHclkPara").val()),
            parseInt($("#ledGrayScale").val()), parseInt($("#ledHclkCycle").val()),
            parseInt($("#ledclkmultiple").val()),
            parseInt($("#scanHclkDelay").val()), 0,
            parseInt($("#scanBlankingTime").val()),
            parseInt($("#scanMultParam").val()), parseInt($("#scanDataDirection").val()),
            parseInt($("#dispalyMSBTimeMult").val()));

        var jsonval = {};

        if ($("#yerOrNo").is(":checked")) {
            if (RegExpKuo() == false) {
                return false;
            }

            jsonval = {
                "width": $("#param input:first").val(),
                "height": $("#param input:eq(1)").val(),
                "totalProgram": $("#param input:eq(2)").val(),
                "color": $("#color").val(),
                "oep": $("#check input:eq(0)").val(),
                "dap": $("#check input:eq(1)").val(),
                "nvertedByte": $("#check input:eq(2)").val(),
                "sync": 0,
                "warning": 0,
                "sms": 0,
                "extend": kuoarr
            };

        } else {
            jsonval = {
                "width": $("#param input:first").val(),
                "height": $("#param input:eq(1)").val(),
                "totalProgram": $("#param input:eq(2)").val(),
                "color": $("#color").val(),
                "oep": $("#check input:eq(0)").val(),
                "dap": $("#check input:eq(1)").val(),
                "nvertedByte": $("#check input:eq(2)").val(),
                "sync": 0,
                "warning": 0,
                "sms": 0,
                "extend":[]
            };
        }
        console.log("你" + JSON.stringify(jsonval))
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('dev_szz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 21, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'),domain.language.$t('dev_chengg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });
    });


    /**单击音量设置 */
    $("#volume").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if (($("#VolumnValue").val()) < 1 || ($("#VolumnValue").val()) > 10) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_yl10'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        var jsonval = new Array();
        jsonval.push(
            {
                "beginTime": "00:00",
                "volumnValue": $("#VolumnValue").val()

            }
        );
        //  alert(jsonval);
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 131, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "volumnType": 1, "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });

    $("#brightness input[type='number']").bind('input propertychange', function () {

        if ($(this).val() == "") {

            $(this).val(0);
        }
        var val = $(this).val().substr(0, 1);
        if (val == "0") {
            $(this).val(0);
        }
    });

    /**调节亮度 */
    $("#light").click(function () {
        var idval = defaull();

        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        var lightflag = false;
        //提示亮度值范围
        $("#brightness input[type='number']").each(function (i) {
            if ($(this).val() == "") {

                swal(domain.language.$t('dev_omg'),domain.language.$t('dev_ldbwk'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                lightflag = true;
                return;
            }
            if ($(this).val() < 0 || $(this).val() > 15) {
                swal(domain.language.$t('dev_omg'),domain.language.$t('dev_ld15'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                lightflag = true;
                return;
            }
        });

        if (lightflag == true) {
            return false;
        }

        var jsonval = new Array();

        //取时间的值
        var time = "";
        var timeArr = [''];
        var lightType = 0;
        for (var i = 0; i < $("#timeCount").val(); i++) {
            var ii = parseInt(i) + 1;
            time = "";//到下一轮清空
            $("#timer" + ii).find("input[type='text']").each(function (i) {

                time += $(this).val();
            });
            if ($("#timeCount").val() == "1") {
                lightType = 1;
            }

            timeArr[i] = time;
            if (i >= 1) {
                i
                if (getNowFormatDate() + " " + timeArr[i] <= getNowFormatDate() + " " + timeArr[i - 1]) {

                    swal(domain.language.$t('dev_shibai'), domain.language.$t('dev_di') + (i + 1) + domain.language.$t('dev_gsjbxysyg'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                    return false;
                }

            }
            jsonval.push({
                "lightBeginTime": timeArr[i],
                "lightValue": $("#brightness").find("input[type='number']:eq(" + i + ")").val()

            });
            console.log(JSON.stringify(jsonval));

        }

        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 28, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "lightType": lightType,
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });


    });


    /**设置GPRS通信**/
    $("#GPRS").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if ($("#ip").val() != "") {
            if (isValidIP($("#ip").val()) == false) {
                swal(domain.language.$t('dev_omg'), domain.language.$t('dev_IPbzq'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
        }
        if (parseInt($("#port").val()) < 4000 || parseInt($("#port").val()) > 65536) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_cdkwx'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }


        var jsonval = {
            "apn": $("#APN").val(),
            "userName": $("#userName").val(),
            "password": $("#userPwd").val(),
            "dns": $("#DNS").val(),
            "domain": $("#ip").val(),
            "port": $("#port").val(),
            "ipType": $("#ipType").val(),
            "is4G": $("#is4G").val()

        };
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 52, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);

                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    // alert(123);
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });
    });


    /**回读基本参数**/
    $("#readParam").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }


        if (idvalnumber.length > 12) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_znhdyg'), "error");
            $(".confirm").text(domain.language.$t('queding'));

        } else {
            $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('dev_zzdqz') });
            $.ajax({
                type: "post",
                url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                dataType: "text",
                timeout: 15000,//超时设置
                data: {
                    "sessionid": sessionStorage.getItem("sid"), "cmd": 30, "devicenumber": idval,
                    "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")

                },
                success: function (data) {

                    $.fn.jqLoading("destroy");
                    data = JSON.parse(data);
                    console.log(data);
                    if (data != "") {

                        if (data.status == "error") {
                            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_hdsb'), "error");
                            $(".confirm").text(domain.language.$t('queding'));
                        } else {

                            swal(domain.language.$t('dev_success'), domain.language.$t('dev_hdcg'), "success");
                            $(".confirm").text(domain.language.$t('queding'));
                            $("#param input:first").val(data.RowPointNum);
                            $("#param input:eq(1)").val(data.ColPointNum);
                            $("#param input:eq(2)").val(data.ProgramTotal);

                            var maxIndex = $("#color option:last").val();//获取select最大的索引
                            for (var i = 0; i < maxIndex; i++) {
                                $("#color option[value='" + data.Color + "']").attr("selected", "selected");//值匹配对的，设为选中

                            }
                        }

                    } else {
                        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_hdsb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));
                    }

                }
            });
        }
    });

    /**回读GPRS通信**/
    $("#readGPRS").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if ((device).length > 12) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_znhdyg'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('dev_zzdqz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 63, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")
            },

            success: function (data) {
                console.log(data);
                // data = JSON.parse(data);
                $.fn.jqLoading("destroy");
                data = eval("(" + data + ")");   //转json格式
                //alert(data.IP_Type);
                if (data != "") {
                    if (data.status == "error") {
                        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_hdsb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));
                    } else {
                        swal(domain.language.$t('dev_success'), domain.language.$t('dev_hdcg'), "success");
                        $(".confirm").text(domain.language.$t('queding'));
                        //{"IP_Type":"1","IP":"","Port":"6669","USERNAME":"","USERPWD":"","DNS":"lgsv2019.tpddns.cn","is4G":"1","APN":"cmiot"}
                        $("#APN").val(data.APN);
                        $("#userName").val(data.USERNAME);
                        $("#userPwd").val(data.USERPWD);
                        $("#DNS").val(data.DNS);
                        $("#ip").val(data.IP);
                        $("#port").val(data.Port);

                        // 
                        $("#ipType").val(data.IP_Type);

                        if (data.is4G == "1") {
                            $("#is4G").attr("checked", true);
                            $("#is4G").val("1");
                        }
                        if (data.DNS != "") {
                            $("#DNS").attr("readonly", false);
                            $("#ip").attr("readonly", true);

                        } else {
                            $("#DNS").attr("readonly", true);
                            $("#ip").attr("readonly", false);

                        }

                    }

                } else {
                    swal(domain.language.$t('dev_omg'), domain.language.$t('dev_hdsb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }

            }
        });





    });


    /**波特率 */
    $("#cuanSet").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if ($("#p_Adrr").val() == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_qxztxdz'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        //提示等待时间范围
        var waitTime = $("#waitTime").val();
        if (waitTime == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_qxzddsj'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if (waitTime < 1 || waitTime > 15) {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_ddsj15'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }


        var jsonval = {
            "address": $("#p_Adrr").val(),
            "baudRate": $("#baudRate").val(),
            "waitTime": $("#waitTime").val()
        };

        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 48, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });


    //继电器
    $("#bagSet").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        var jsonval = {
            "BagID": 0,
            "Offset": 0
        };


        //  alert(jsonval);
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 160, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });

    //扫描配置
    $("#scanSet").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        var jsonval = {
            "rowOrder": $("#rowOrder").val(),
            "pointFreq": 0,
            "lineShadow": $("#lineShadow").val(),
            "rgOrder": $("#RGOrder").val(),
            "mirror": $("#mirror").val(),
            "decoding": $("#have138").val(),
            "scanType": $("#scanType").val()

        };


        //  alert(jsonval);
        $.fn.jqLoading({ height: 100, width: 240, text:domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 16, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'),domain.language.$t('dev_chengg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szshibai'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });


    //升级固件
    $('#send').click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if (fileId == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_scwjbwk'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }



        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });

        $.ajax({
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            type: 'POST',
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 65, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "fileId": fileId
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('dev_chengg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                    $("#file1").prev().val(domain.language.$t('dev_xzwenjian'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });


    //  //升级字库
    $('#upgrade').click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if (fileId == "") {
            swal(domain.language.$t('dev_omg'),domain.language.$t('dev_scwjbwk') , "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }



        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });

        $.ajax({
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            type: 'POST',
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 85, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "fileId": fileId
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('dev_chengg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                    $("#file2").prev().val(domain.language.$t('dev_xzwenjian'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });

    });


    //扫描方式
    seleScanMode();

    //执行操作
    $("#control").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        //console.log("值" + parseInt($("#option").val()));
        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": parseInt($("#option").val()), "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")
            },

            success: function (data) {
                data = JSON.parse(data);

                if (data.code == "200") {
                    $.fn.jqLoading("destroy");

                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });
    });

    //开关屏
    $("#setOption").click(function () {
        var idval = defaull();

        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        var jsonval = new Array();

        //取时间的值
        var stime = ""; var etime = "";
        var sArr = ['']; var eArr = [''];

        for (var i = 0; i < $("#timeScreenCount").val(); i++) {
            var ii = parseInt(i) + 1;
            stime = "";//到下一轮清空
            etime = "";
            $("#stimer" + ii).find("input[type='text']").each(function (i) {
                stime += $(this).val();
            });
            $("#etimer" + ii).find("input[type='text']").each(function (i) {
                etime += $(this).val();
            });

            sArr[i] = stime;
            eArr[i] = etime;

            if (getNowFormatDate() + " " + sArr[i] >= getNowFormatDate() + " " + eArr[i]) {

                swal(domain.language.$t('dev_shibai'), domain.language.$t('dev_ksskbdyjs'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return false;
            }
            if (i >= 1) {
                if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {

                    swal(domain.language.$t('dev_shibai'), domain.language.$t('dev_di') + ii + domain.language.$t('dev_gsjbxysyg'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                    return false;
                }
                if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + sArr[i - 1]) {

                    swal(domain.language.$t('dev_shibai'), domain.language.$t('dev_di') + ii + domain.language.$t('dev_sjbxsgsd'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                    return false;
                }
                if (getNowFormatDate() + " " + eArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {
                    //console.log("mj"+eArr[i])
                    swal(domain.language.$t('dev_shibai'), domain.language.$t('dev_di') + ii + domain.language.$t('dev_sjbxsgsd'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                    return false;
                }

            }
            jsonval.push({ "start": sArr[i], "end": eArr[i] });
            console.log("开关屏" + JSON.stringify(jsonval));

        }

        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 23, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });


    });

    //五星个数 
    $("#Taxi_Five").change(function () {
        $("#wx td").hide();

        for (var i = 0; i < $(this).val(); i++) {

            $("#wx td").eq(i).show();

        }

    });

    //五星好评
    $("#addpf").click(function () {

        var isChecked = $('#wxis').is(":checked");
        isChecked = isChecked == true ? "1" : "0";
        var color_five_buff = new Array();

        $("#wx td").each(function () {

            var display = $(this).css('display');

            if (display != 'none') {
                color_five_buff.push($(this).find("select").val());
            }
        });

        //console.log("有nn" + JSON.stringify(color_five_buff));
        var idval = defaull();
        if (idval == "") {

            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('zzbcz')});
        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            data: {
                "colors": JSON.stringify(color_five_buff), "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "cmd": "178", sessionid: sessionStorage.getItem("sid")
            },
            //timeout: 5000,//超时设置
            success: function (response) {
                response = JSON.parse(response);
                if (response.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'),  domain.language.$t('baocuncg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('baocunsb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (data) {
                $.fn.jqLoading("destroy");
                swal(domain.language.$t('dev_omg'),  domain.language.$t('baocunsb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            }
        });
    });


    //星级设置
    $("#setXing").click(function () {

        var idval = defaull();
        if (idval == "") {

            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        $.fn.jqLoading({ height: 100, width: 240, text:domain.language.$t('zzbcz')});
        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            data: {
                "lightCount": $("#lightCount").val(), "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "cmd": "179", sessionid: sessionStorage.getItem("sid")
            },
            //timeout: 5000,//超时设置
            success: function (response) {
                response = JSON.parse(response);
                if (response.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('baocuncg'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'),domain.language.$t('baocunsb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (data) {
                $.fn.jqLoading("destroy");
                swal(domain.language.$t('dev_omg'), domain.language.$t('baocunsb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            }
        });
    });
});

$(function () {
    


    //设备操作
    $("#ok").click(function () {
        var type = ""; var sbhao = "";
        var type2 = ""; var sbhao2 = ""; var cooid = "";
        var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");

        //遍历访问这个集合
        $(ids).each(function (index, id) {
            //由id获得对应数据行
            var row = $("#table_list_1").jqGrid('getRowData', id);
            // console.log(row);
            cooid = row.co_id;
            if (row.type == domain.language.$t('dev_sblx1_ds')) {

                sbhao += row.devicenumber + ","; type = 0;

            }
            if (row.type == domain.language.$t('dev_sblx2_ss')) {

                sbhao += row.devicenumber + ","; type = 1;
            }
            if (row.type == domain.language.$t('dev_sblx3_qc')) {

                sbhao2 += row.devicenumber + ",";
                type2 = 2;
            }
            if (row.type ==domain.language.$t('dev_sblx4_az')) {

                sbhao2 += row.devicenumber + ",";
                type2 = 3;
            }
            //console.log("row.ID:"+row.programid);
        });
        sbhao = sbhao.substring(0, sbhao.length - 1);
        sbhao2 = sbhao2.substring(0, sbhao2.length - 1);
        if (sbhao == "" && sbhao2 == "") {
            swal("", domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if (sbhao.length > 0) {
            $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
            $.ajax({
                url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                type: "post",
                dataType: "json",
                timeout: 1000000,//超时设置
                data: { "sessionid": sessionStorage.getItem("sid"), "companyId": cooid, "devicenumber": sbhao, "cmd": $("#zl").val(), "deviceType": type },
                success: function (data) {


                    if (data.code == "200") {
                        $.fn.jqLoading("destroy");
                        swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                        $(".confirm").text(domain.language.$t('queding'));
                    } else {
                        $.fn.jqLoading("destroy");
                        swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));
                    }
                }, error: function (data) {

                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));

                },
                complete: function (XMLHttpRequest, status) {

                    if (status == 'timeout') {
                        $.fn.jqLoading("destroy");
                        swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));

                    }
                }
            });
        } else {
            $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
            $.ajax({
                url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                type: "post",
                dataType: "json",
                timeout: 5000000,//超时设置
                data: { "sessionid": sessionStorage.getItem("sid"), "companyId": cooid, "devicenumber": sbhao2, "cmd": $("#zl").val(), "deviceType": type2 },
                success: function (data) {


                    if (data.code == "200") {
                        $.fn.jqLoading("destroy");
                        swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                        $(".confirm").text(domain.language.$t('queding'));


                    } else {
                        $.fn.jqLoading("destroy");
                        swal("", domain.language.$t('xiafasb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));
                    }
                }, error: function (data) {

                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }, complete: function (XMLHttpRequest, status) {

                    if (status == 'timeout') {
                        $.fn.jqLoading("destroy");
                        swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                        $(".confirm").text(domain.language.$t('queding'));
                    }
                }
            });

        }



    });


    //空车有客
    $("#setCar").click(function () {
        var isChecked = $('#wxis').is(":checked");
        isChecked = isChecked == true ? "1" : "0";
        var color_five_buff = new Array();

        $("#kcar select").each(function () {

            color_five_buff.push($(this).val());
        });
        var idval = defaull();

        if (idval == "") {

            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            data: {
                "statusColor": JSON.stringify(color_five_buff), "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "cmd": "180", sessionid: sessionStorage.getItem("sid")
            },
            //timeout: 5000,//超时设置
            success: function (response) {
                response = JSON.parse(response);
                if (response.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (data) {
                $.fn.jqLoading("destroy");
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            }
        });
    });

    //取消报警
    $("#cancall").click(function () {
        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }


        $.fn.jqLoading({ height: 100, width: 240, text: domain.language.$t('xiafazlz') });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 177, "devicenumber": idval,
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "state": 0
            },

            success: function (data) {
                data = JSON.parse(data);

                if (data.code == "200") {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));

                } else {
                    $.fn.jqLoading("destroy");
                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            }, error: function (response, ajaxOptions, thrownError) {

                $(".mloading-mask").hide();
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            },
        });


    });
  

    //报警内容为空时，默认内容
$("#list3 li:eq(1)").click(function(){
    
if($("#savetext").val()==""){

    $("#savetext").val(domain.language.$t('dev_bjneirong'));
}
});

    //设置报警
    $("#sendSOS").click(function () {

        var idval = defaull();
        if (idval == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('qxzshebei'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }
        if ($("#savetext").val().trim() == "") {
            swal(domain.language.$t('dev_omg'), domain.language.$t('dev_bjnrbwk'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        if ($("#savetext").val().length > 200) {
            swal(domain.language.$t('dev_omg'),domain.language.$t('dev_srnrcg200'), "error");
            $(".confirm").text(domain.language.$t('queding'));
            return;
        }

        $.fn.jqLoading({ height: 100, width: 240, text:domain.language.$t('xiafazlz') });

        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/programManagement/sendbaojin",
            data: { sessionid: sessionStorage.getItem("sid"), "devicenumber": idval, "companyid": sessionStorage.getItem("coid"), "text": $("#savetext").val() },

            success: function (response) {
                response = JSON.parse(response);
                $.fn.jqLoading("destroy");
                if (response.code == "200") {

                    swal(domain.language.$t('dev_success'), domain.language.$t('zlyxf'), "success");
                    $(".confirm").text(domain.language.$t('queding'));

                } else {

                    swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                    $(".confirm").text(domain.language.$t('queding'));

                }
            }, error: function (response, ajaxOptions, thrownError) {

                $.fn.jqLoading("destroy");
                swal(domain.language.$t('dev_omg'), domain.language.$t('xiafasb'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            }
            
        });

    });

});



// function ledChipSelect(){
//     var ledColumnChip=new Array();
//     var ledRowChip=new Array();
//     ledColumnChip=[{"默认列芯片","SM16207","SM16227","SM16237","icn2038S/2045CN","ICN2053"," SUM2017",
//                     "MBI5024普通芯片","FM6126A","SM16159","SM16259","icn2055","sum2035"}];

    
//    }



//扫描方式
window.seleScanMode = function () {

    $.ajax({
        type: "post",
        url: domain.testUrl + "/Threeinjection/DeviceManagement/queryScanModeInfo",
        dataType: "text",
        timeout: 1500,//超时设置
        data: { "sessionid": sessionStorage.getItem("sid") },
        success: function (data) {
            var data2 = JSON.parse(data);
            var arr = data2.ScanModeInfo;//json数组
            if (arr != "" || arr != null) {
                for (var i = 0; i < arr.length; i++) {
                    //$("#scanType").append("<option value=" + arr[i].scanType + arr[i].subscanType + ">" + arr[i].scanName + "</option>");

                }
                console.log("扫描方式获取成功！");

            } else {
                $("#scanType").append("<option>"+domain.language.$t('dev_no')+"</option>");
            }

        }
    });
}

//日期（时间需要加日期一起）
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

Date.prototype.Format = function (fmt) {
    //author:wangweizhen
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


//扩展参数的正则判断
window.RegExpKuo = function () {
    if ($("#ledHclkPara").val().trim() == "") {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szycbk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if ($("#ledHclkCycle").val().trim() == "") {

        swal(domain.language.$t('dev_omg'),domain.language.$t('dev_szzqbk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if ($("#dispalyMSBTimeMult").val().trim() == "") {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_yxldbwk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }

    if ($("#scanHclkDelay").val().trim() == "") {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szysbk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if ($("#scanMultParam").val().trim() == "") {

        swal(domain.language.$t('dev_omg'),domain.language.$t('dev_sxblbk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if ($("#scanBlankingTime").val().trim() == "") {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_xysjbk'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }


    if (parseInt($("#ledHclkPara").val()) < 4 || parseInt($("#ledHclkPara").val()) > 255) {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szyc255'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if (parseInt($("#ledHclkCycle").val()) < 3 || parseInt($("#ledHclkCycle").val()) > 15) {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_szqz15'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if (parseInt($("#scanHclkDelay").val()) < 0 || parseInt($("#scanHclkDelay").val()) > 7) {

        swal(domain.language.$t('dev_omg'),domain.language.$t('dev_szys7'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    if (parseInt($("#scanBlankingTime").val()) < 8 || parseInt($("#scanBlankingTime").val()) > 255) {

        swal(domain.language.$t('dev_omg'), domain.language.$t('dev_xysj255'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }


    else {
        $("#modalLong").hide();
    }
}


//获取选中卡号
window.defaull = function () {
    //选中的卡号
    var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");
    var idval = "";
    //遍历访问这个集合
    $(ids).each(function (index, id) {
        //由id获得对应数据行
        var row = $("#table_list_1").jqGrid('getRowData', id);
        idval += row.devicenumber + ",";

    });
    if (idval.indexOf(",") != -1) {
        idval = idval.substring(0, idval.length - 1);
    }

    return idval;
}

//点击菜单栏事件
window.displayMenu = function (i, th) {

    var display = $(".right-content .row:eq(" + i + ")");
    $(".right-content .row").hide();
    if($("#modalLong").css('display') != "none"){
        $("#modalLong").css('display','none'); 
    }
    $(".right-content .row:eq(" + i + ")").show();
    if (display.css('display') != "none") {

        $("#list1 li,#list2 li,#list3 li").css("background", "white");
        $(th).css("background", "#f2f2f2");
    }


}




window.clickfile=function(node){
  $(node).next().click();
}